/*
 * Eugen Stoian <stoian.e@gmail.com> 2010
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef INTERVAL_H
#define INTERVAL_H
#include <QString>
class Interval
{
public:
    Interval(double inf = 0.0, double sup=0.0, bool leftClosed = true, bool rightClosed = true);
    Interval(const Interval& interval);
    Interval& operator=(const Interval& interval);
    Interval(const QString& s);
    inline double inf() const{
        return _inf;
    }
    inline void setInf(double inf){
        _inf = inf;
    }
    inline double sup() const{
        return _sup;
    }
    inline void setSup(double sup){
        _sup = sup;
    }
    inline double length() const {
        return _sup-_inf;
    }
    inline bool isClosedToLeft() const {
        return _leftClosed;
    }
    inline bool isClosedToRight() const {
        return _rightClosed;
    }
    inline bool isClosed() const {
        return _rightClosed && _leftClosed;
    }
    bool contains(double value) const;

    operator QString() const;

    inline operator bool() const{
        if(!isClosed())
            return _sup>_inf;
        return _sup>=_inf;
    }
    double first() const;
    double last() const;
private:
    double _inf;
    double _sup;
    bool _leftClosed;
    bool _rightClosed;
};

#endif // INTERVAL_H
